<template>
    <!-- start:自定义页面内容 -->
            <div>
            <span class="tips" v-if="cmiid==='1596'" >请按图示位置，芯片朝上插入医保卡后，按"确定读卡"按钮</span>
            <span class="tips" v-if="cmiid==='104'" >请按图示位置，芯片朝上插入医保卡后，按"确定读卡"按钮。不插卡按"确定读卡"按钮，可扫描电子医保卡</span>
            <el-card class="box-card">
            <el-image :src="readingUrl">
            </el-image>
          </el-card>
           <el-button class="conbut" @click="Readsbk()" type="primary" size="middle">确定读卡</el-button>
        </div>
    <!-- end:自定义页面内容 -->
</template>

<script>
import readingYbk from "@images/readcard/reading03.png";
import { MessageBox } from "element-ui"
import { CallMedIns } from "@api/tools/MedInsTrade.js";
import moment from "moment";
export default {
  name: "Sbkdk",
  data() {
    return {
      YB: new CallMedIns(),
      cardNo: "",
      cmiid:this.$store.state.terminfo.orginfo.cmiid,
      readingUrl:this.loginUrl
    };
  },
    props:{
    loginUrl:String,
  },
  methods: {
    async Readsbk() {
      console.log('%c Begin医保卡读卡', 'color:#01DFA5');
      if(this.destroyed) {
        return; // 防止页面关闭后 继续调用
      }
      ///////////////////////////// 异步写法
      try{
        var param ='';
        var datetime = moment().format("YYYYMMDDHHmmSS");
        let orginfo = this.$store.state.terminfo.orginfo;
        let termId = this.$store.state.terminfo.terminfo.termId;
        var operno=orginfo.cmiid+termId.substr(2,1)+termId.substr(4,2);
        console.log("业务周期号",this.$store.state.terminfo.medInsBusinessInfo);
        if(orginfo.cmiid==='104'){
             param="2100^"+orginfo.cmiid+"^" + operno + "^" + this.$store.state.terminfo.medInsBusinessInfo+ "^" + datetime +orginfo.cmiid + "011^0000^^1^";
        }
        else {
           param = "2100^"+orginfo.cmiid+"^" + operno + "^" + this.$store.state.terminfo.medInsBusinessInfo+ "^1^" + datetime +orginfo.cmiid + "011^^^";
        }
       console.log('param= '+param);
        var readedinfo =await this.YB.Trade(1, param);
        console.log('readedinfo= ',readedinfo);
        if(readedinfo!= '') {
          this.$emit('ReadedSbkCard',readedinfo)
        } else {
          this.timerhandle = setTimeout(()=>this.Readsbk(), 500);
        }
      } catch(e) {
        console.log(`%c error: ${e.message}`, 'color:red');
        setTimeout(() => {this.$router.push({ name: "home" }); }, 500);
      }
    },
  },
  mounted() {
  //  this.timerhandle = setTimeout(()=>this.Readsbk(), 2000);
  }
};
</script>

<style scoped>
.conbut{
  margin-left: 800px;
  margin-top: 50px;
  font-size: 30px;
}
.tips{
  color:rgb(230, 23, 23);
  font-size: 30px;
  margin-bottom: 100px;
}
</style>
